package com.example.forjava.write;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class FastFile2Writer {
    public static void main(String[] args) {
        String filePath = "D:\\output.txt";
        int totalLines = 500000;

        List<String> lines = new ArrayList<>(totalLines);
        for (int i = 0; i < totalLines; i++) {
            lines.add("docker run -d --hostname=rabbitmqhost -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -e RABBITMQ_DEFAULT_VHOST=my_vhost -vdocker run -d --hostname=rabbitmqhost -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -e RABBITMQ_DEFAULT_VHOST=my_vhost -v  " + i);
        }

        try {
            long startTime = System.currentTimeMillis();
            Files.write(Paths.get(filePath), lines);
            long endTime = System.currentTimeMillis();
            System.out.println("写入完成，耗时：" + (endTime - startTime) + " 毫秒");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}